package org.fitweb.fixture;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class XmlFormatterTest {
    private static final String ORIGINAL = "<item uniqueId=\"2\">\n" + "        <name>example item 2</name>\n" + "        <description>A little like the one above</description>\n" + "    </item>";

    private static final String NO_UNNECESSARY_WHITESPACE = "<item uniqueId=\"2\"><name>example item 2</name><description>A little like the one above</description></item>";

    private static final String TAGS_UPPERCASE = "<ITEM UNIQUEID=\"2\">\n" + "        <NAME>example item 2</NAME>\n" + "        <DESCRIPTION>A little like the one above</DESCRIPTION>\n" + "    </ITEM>";

    @Test
    public void testCanRemoveWhitespaceFromXml() {
        assertEquals(NO_UNNECESSARY_WHITESPACE, new XmlFormatter(ORIGINAL).withUnnecessarySpacesRemoved().toString());
    }

    @Test
    public void testCanUpperCaseTags() {
        assertEquals(TAGS_UPPERCASE, new org.fitweb.fixture.XmlFormatter(ORIGINAL).withTagsUpperCase().toString());
    }

    @Test
    public void addsLinebreaksToXml() {
        String input = "<xml><tag>monkeys</tag></xml>";
        String expectedOutput = "" + "<xml>\n" + "<tag>monkeys</tag>\n" + "</xml>";

        String result = new XmlFormatter(input).withUnnecessarySpacesRemoved().withLineBreaks().toString();

        assertEquals(expectedOutput, result);
    }

    @Test
    public void addsIndentationToXml() {
        String input = "" + "<xml>\n" + "<tag>monkeys</tag>\n" + "<eat>\n" + "<bunchesOf>bananas</bunchesOf>\n" + "</eat>\n" + "</xml>\n";
        String expectedOutput = "" + "<xml>\n" + "    <tag>monkeys</tag>\n" + "    <eat>\n" + "        <bunchesOf>bananas</bunchesOf>\n" + "    </eat>\n" + "</xml>\n";

        String result = new XmlFormatter(input).withIndentation(4).toString();

        assertEquals(expectedOutput, result);
    }
}
